package com.linhngua.code.gwt.server;


import java.io.IOException;


import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import org.jboss.resteasy.plugins.providers.multipart.InputPart;
import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput;
import org.jboss.resteasy.plugins.providers.multipart.MultipartInputImpl.PartImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Path("/image")
public class ImageRS {

	private static final Logger LOG = LoggerFactory.getLogger(ImageRS.class);

	@POST
	@Consumes("multipart/form-data")
	public Response receiveImage(MultipartFormDataInput input)
			throws IOException {

		for (InputPart inputPart : input.getParts()) {
			//MediaType mediaType = inputPart.getMediaType();
			// image
		//	if (MediaType.APPLICATION_OCTET_STREAM_TYPE.isCompatible(inputPart
		//			.getMediaType())) {
				//cast
				PartImpl partImpl=(PartImpl)inputPart;
				String s=partImpl.getBodyAsString();
				LOG.info("Received "+s);
					
			//}
		}
		return Response.ok().build();
	}
	
	@GET
	@Path("/hello")
	public String hello(){
		return "hello";
	}
}
